package com.TeamJigsaw.DanteTrail.Models;

import java.util.List;
import java.util.Random;

import javax.swing.JOptionPane;

import com.TeamJigsaw.DanteTrail.Views.MainViewFrame;

/**
 * A random illness strikes one of you party members.
 * @author Vince
 *
 */
public class IllnessEvent extends RandomEvent {

	private List<PartyMember> partyMembers;
	
	private Random generator;
	
	private String eventMessage;
	
	private MainViewFrame mainView;
	
	public IllnessEvent (Party party, MainViewFrame mainView){
		partyMembers = party.getParty();
		generator = new Random();
		eventMessage = null;
		this.mainView = mainView;
	}
	
	@Override
	public boolean performEvent(Party party) {
		int randNum = generator.nextInt(101);
		int pace = party.getPace();
		double multiply = 0.00;
		if (pace == 5){
			multiply = 1.20;
		}
		else if (pace == 10){
			multiply = 1.15;
		}
		else if (pace == 15){
			multiply = 1.10;
		}
		else if (pace == 20){
			multiply = 1.05;
		}
		
		double newRand = randNum * multiply;
		
		if (newRand > 100){
			randNum = generator.nextInt(3);
			PartyMember currMember = partyMembers.get(randNum);
			if (currMember.getHealth() == 1){
				currMember.setStatus(1); //Set this party member to dead.
				eventMessage = currMember.getName() + " has died.";
				int sum = 0;
				for (int i = 0; i < 3; i++){
					if (partyMembers.get(i).getStatus() == 1){
						sum++;
					}
				}
				if (sum == 3){
					//TODO actually put this into the "Game Over" screen"
					JOptionPane.showMessageDialog(mainView, "Game Over! You party is all dead");
				}
			}
			else {
				currMember.setHealth(1); //This party member is now ill.
				eventMessage = currMember.getName() + " is now ill";
			}
			
			return true;
		}

		return false;
	}

	@Override
	public String getMessage() {
		return eventMessage;
	}

}
